﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Enterprise.Infrastructure;
using Enterprise.Model.Vote;
using Enterprise.Service.Vote;
namespace Enterprise.UI.Web.Modules.Vote
{
    public partial class Manage : Enterprise.Service.BasePage
    {
        string vId = (string)Utility.sink("vId", Utility.MethodType.Get, 0, 0, Utility.DataType.Str);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                OnStart();
            }
        }

        private void OnStart()
        {
            OnBindVoteItem();
            tb_EndTime.Text = DateTime.Now.AddMonths(1).ToShortDateString();
        }

        private void OnBindVoteItem()
        {
            VoteItemService viService = new VoteItemService();
            var list = viService.VoteItemList(vId).OrderBy(p => p.VITEMCODE);
            GridView1.DataSource = list;
            GridView1.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
             string _note = "操作成功";
             try
             {
                 VoteService vService = new VoteService();
                 VoteEntity entity = new VoteEntity();
                 entity.VID = vId;
                 entity.VTITLE = (string)Utility.sink(tb_Title.UniqueID, Utility.MethodType.Post, 0, 0, Utility.DataType.Str);
                 entity.VTYPE = 0;
                 entity.VENDTIME = (DateTime)Utility.sink(tb_EndTime.UniqueID, Utility.MethodType.Post, 0, 0, Utility.DataType.Date);
                 //签收范围格式@1,4,5
                 string rcv_users = rcv_users_value.Value;
                 rcv_users = rcv_users.TrimEnd(',');
                 entity.VRANGE = rcv_users;
                 entity.VREMARK = (string)Utility.sink(tb_Content.UniqueID, Utility.MethodType.Post, 0, 0, Utility.DataType.Str);
                 entity.VCREATEUSER = Utility.Get_UserId;
                 entity.VCREATETIME = DateTime.Now;
                 entity.VMIX = 0;
                 entity.VMAX = 0;
                 entity.VPUBLIC = 0;
                 entity.VPUBLICTIME = DateTime.Now;
                 entity.DB_Option_Action = "Insert";
                 vService.VoteExecute(entity);
             } 
            catch (Exception ex)
            {
                _note = ex.Message;
            }
            Utility.ShowMsg(this.Page, "OK", this.Tran(_note), "Index.aspx");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            VoteItemService viService = new VoteItemService();
            VoteItemEntity entity = new VoteItemEntity();
            entity.VID = vId;
            entity.VITEMCODE = (string)Utility.sink(tb_Item.UniqueID, Utility.MethodType.Post, 0, 0, Utility.DataType.Str);
            entity.VITEMTITLE = (string)Utility.sink(tb_ItemTitle.UniqueID, Utility.MethodType.Post, 0, 0, Utility.DataType.Str);
            entity.VITEMREMARK = "";
            entity.DB_Option_Action = "Insert";
            viService.VoteItemExecute(entity);
            OnBindVoteItem();
        }
    }
}